<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />

  <title>Class: RawJsonRpc::RawClientJsonRpc</title>

  <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

  <script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/darkfish.js" type="text/javascript" charset="utf-8"></script>

</head>
<body id="top" class="class">

  <div id="metadata">
    <div id="home-metadata">
      <div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
      </div>
    </div>

    <div id="file-metadata">
      <div id="file-list-section" class="section">
        <h3 class="section-header">In Files</h3>
        <div class="section-body">
          <ul>
          
            <li><a href="../lib/rawjsonrpc/client_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
              class="thickbox" title="lib/rawjsonrpc/client.rb">lib/rawjsonrpc/client.rb</a></li>
          
          </ul>
        </div>
      </div>

      
    </div>

    <div id="class-metadata">
      
      <!-- Parent Class -->
      <div id="parent-class-section" class="section">
        <h3 class="section-header">Parent</h3>
        
        <p class="link">Object</p>
        
      </div>
      

      

      

      
      <!-- Method Quickref -->
      <div id="method-list-section" class="section">
        <h3 class="section-header">Methods</h3>
        <ul class="link-list">
          
          <li><a href="#method-i-get_response">#get_response</a></li>
          
          <li><a href="#method-i-method_missing">#method_missing</a></li>
          
          <li><a href="#method-i-notification">#notification</a></li>
          
          <li><a href="#method-i-request">#request</a></li>
          
          <li><a href="#method-i-send_request">#send_request</a></li>
          
        </ul>
      </div>
      

      
    </div>

    <div id="project-metadata">
      
      
      <div id="fileindex-section" class="section project-section">
        <h3 class="section-header">Files</h3>
        <ul>
        
          <li class="file"><a href="../README_rdoc.html">README.rdoc</a></li>
        
        </ul>
      </div>
      

      <div id="classindex-section" class="section project-section">
        <h3 class="section-header">Class/Module Index
          <span class="search-toggle"><img src="../images/find.png"
            height="16" width="16" alt="[+]"
            title="show/hide quicksearch" /></span></h3>
        <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
        <fieldset>
          <legend>Quicksearch</legend>
          <input type="text" name="quicksearch" value=""
            class="quicksearch-field" />
        </fieldset>
        </form>

        <ul class="link-list">
        
          <li><a href="../RawJsonRpc.html">RawJsonRpc</a></li>
        
          <li><a href="../RawJsonRpc/ClientSock.html">RawJsonRpc::ClientSock</a></li>
        
          <li><a href="../RawJsonRpc/RawClientJsonRpc.html">RawJsonRpc::RawClientJsonRpc</a></li>
        
          <li><a href="../RawJsonRpc/RawServerJsonRpc.html">RawJsonRpc::RawServerJsonRpc</a></li>
        
          <li><a href="../RawJsonRpc/ServerSocket.html">RawJsonRpc::ServerSocket</a></li>
        
          <li><a href="../RawJsonRpc/TCPServer.html">RawJsonRpc::TCPServer</a></li>
        
          <li><a href="../RpcError.html">RpcError</a></li>
        
        </ul>
        <div id="no-class-search-results" style="display: none;">No matching classes.</div>
      </div>

      
    </div>
  </div>

  <div id="documentation">
    <h1 class="class">RawJsonRpc::RawClientJsonRpc</h1>

    <div id="description" class="description">
      
<p>Implements the base class for all Clients. The class get all methode calls
generate the json data from it</p>

<p><b>Every client must implement <a
href="RawClientJsonRpc.html#method-i-get_response">get_response</a> and <a
href="RawClientJsonRpc.html#method-i-send_request">send_request</a></b>.</p>

<h1>Examples</h1>

<h2>send request</h2>

<pre>client.request(&quot;run&quot;, [1,2,3])                  # calls: run params: 1 2 3
ret = client.request(&quot;attack&quot;, &quot;alpha&quot;, 1, 3.0) # calls: attack
                                                # params &quot;alpha&quot;, 1, 3.0
                                                # returns data into ret</pre>

<h2>send request shortcut</h2>

<pre>client.run([1,2,3])
ret = client.attack(&quot;alpha&quot;, 1, 3.0)</pre>

<h2>send notification (no return value)</h2>

<pre>client.notification(&quot;beat&quot;, [:alpha, 123], &quot;fast&quot;)</pre>

    </div><!-- description -->

    
    
    
    <div id="5Buntitled-5D" class="documentation-section">
      

      

      

      

      <!-- Methods -->
      
      <div id="public-instance-method-details" class="method-section section">
        <h3 class="section-header">Public Instance Methods</h3>

      
        <div id="get_response-method" class="method-detail ">
          <a name="method-i-get_response"></a>

          
          <div class="method-heading">
            <span class="method-name">get_response</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>returns the server response must be implmented</p>
            

            
            <div class="method-source-code" id="get_response-source">
<pre>
<span class="ruby-comment"># File lib/rawjsonrpc/client.rb, line 52</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_response</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;method not overriden&quot;</span>)
<span class="ruby-keyword">end</span></pre>
            </div><!-- get_response-source -->
            
          </div>

          

          
        </div><!-- get_response-method -->

      
        <div id="method_missing-method" class="method-detail ">
          <a name="method-i-method_missing"></a>

          
          <div class="method-heading">
            <span class="method-name">method_missing</span><span
              class="method-args">(name, *args)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>redirect calls</p>
            

            
            <div class="method-source-code" id="method_missing-source">
<pre>
<span class="ruby-comment"># File lib/rawjsonrpc/client.rb, line 36</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">name</span>, *<span class="ruby-identifier">args</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-identifier">request</span>(<span class="ruby-identifier">name</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">request</span>(<span class="ruby-identifier">name</span>, *<span class="ruby-identifier">args</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- method_missing-source -->
            
          </div>

          

          
        </div><!-- method_missing-method -->

      
        <div id="notification-method" class="method-detail ">
          <a name="method-i-notification"></a>

          
          <div class="method-heading">
            <span class="method-name">notification</span><span
              class="method-args">(function_name, *para)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Sends a notification to server. A Notifications don’t return any value</p>
            

            
            <div class="method-source-code" id="notification-source">
<pre>
<span class="ruby-comment"># File lib/rawjsonrpc/client.rb, line 65</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">notification</span>(<span class="ruby-identifier">function_name</span>, *<span class="ruby-identifier">para</span>)
  <span class="ruby-identifier">para</span> = {<span class="ruby-string">'method'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">function_name</span>, <span class="ruby-string">'params'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">para</span>, <span class="ruby-string">'id'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">nil</span>}
    .<span class="ruby-identifier">to_json</span>
  <span class="ruby-identifier">send_request</span> <span class="ruby-identifier">para</span>
  <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- notification-source -->
            
          </div>

          

          
        </div><!-- notification-method -->

      
        <div id="request-method" class="method-detail ">
          <a name="method-i-request"></a>

          
          <div class="method-heading">
            <span class="method-name">request</span><span
              class="method-args">(function_name, *para)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Sends a request to server return a value or raise an RpcException if server
sends an error.</p>
            

            
            <div class="method-source-code" id="request-source">
<pre>
<span class="ruby-comment"># File lib/rawjsonrpc/client.rb, line 73</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">request</span>(<span class="ruby-identifier">function_name</span>, *<span class="ruby-identifier">para</span>)
  <span class="ruby-identifier">id_count</span> = <span class="ruby-identifier">id</span>
  <span class="ruby-identifier">para</span> = {<span class="ruby-string">'method'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">function_name</span>, <span class="ruby-string">'params'</span> =<span class="ruby-operator">&gt;</span>  <span class="ruby-identifier">para</span>, <span class="ruby-string">'id'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">id_count</span>}
    .<span class="ruby-identifier">to_json</span>
  <span class="ruby-identifier">send_request</span>(<span class="ruby-identifier">para</span>)
  <span class="ruby-identifier">result</span> = <span class="ruby-identifier">get_response</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">result</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RpcError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;empty respons&quot;</span>))
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">response</span> = <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">result</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">response</span>[<span class="ruby-string">&quot;error&quot;</span>] <span class="ruby-operator">!=</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RpcError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">response</span>[<span class="ruby-string">&quot;error&quot;</span>]))
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">response</span>[<span class="ruby-string">&quot;id&quot;</span>] <span class="ruby-operator">!=</span> <span class="ruby-identifier">id_count</span>
    <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RpcError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;server send wrong data.&quot;</span>))
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">response</span>[<span class="ruby-string">&quot;result&quot;</span>]
<span class="ruby-keyword">end</span></pre>
            </div><!-- request-source -->
            
          </div>

          

          
        </div><!-- request-method -->

      
        <div id="send_request-method" class="method-detail ">
          <a name="method-i-send_request"></a>

          
          <div class="method-heading">
            <span class="method-name">send_request</span><span
              class="method-args">(para)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Send the request to server must be implmented. takes json string.</p>
            

            
            <div class="method-source-code" id="send_request-source">
<pre>
<span class="ruby-comment"># File lib/rawjsonrpc/client.rb, line 58</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">send_request</span> <span class="ruby-identifier">para</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;method not overriden&quot;</span>)
<span class="ruby-keyword">end</span></pre>
            </div><!-- send_request-source -->
            
          </div>

          

          
        </div><!-- send_request-method -->

      
      </div><!-- public-instance-method-details -->
    
    </div><!-- 5Buntitled-5D -->
  

  </div><!-- documentation -->

  <div id="validator-badges">
    <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
    <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
      Rdoc Generator</a> 2</small>.</p>
  </div>

</body>
</html>

